package com.zhs;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;

@Slf4j
@Getter
@Setter
public class SpringProducer {
    private String producerGroupName;
    private String nameServer;
    private DefaultMQProducer defaultMQProducer;
    public SpringProducer(String producerGroupName, String nameServer ){
        this.producerGroupName=producerGroupName;
        this.nameServer=nameServer;
    }
    public void init() throws Exception{
        log.info("开始启动消息生产者！");
        defaultMQProducer=new DefaultMQProducer(producerGroupName);
        defaultMQProducer.setNamesrvAddr(nameServer);
        defaultMQProducer.start();
        log.info("消息生产者启动成功！");
    }
    public void destory(){
        log.info("开始关闭消息生产者！");
        defaultMQProducer.shutdown();
        log.info("消息生成者关闭成功！");
    }
}
